﻿using Microsoft.EnterpriseManagement.Tracing;
using System;
using System.CodeDom.Compiler;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Diagnostics;


// copied from Microsoft.SystemCenter.Advisor.Internal
// WPP Software Tracing
// http://msdn.microsoft.com/en-us/library/ff556204(v=VS.85).aspx

// with .net 4.5 we could have used system.diagnostics.tracing
// http://blogs.msdn.com/b/vancem/archive/2012/07/09/logging-your-own-etw-events-in-c-system-diagnostics-tracing-eventsource.aspx
// http://blogs.msdn.com/b/vancem/archive/2012/08/13/windows-high-speed-logging-etw-in-c-net-using-system-diagnostics-tracing-eventsource.aspx

// replaced 7ebeb348bd365d5d3f74ae2cd0f9fca5 with 83A9AC932ED24EB7846D1CA9FFBAF79E
//
// had to convert stackalloc void[ in stackalloc byte[ since I get Error	Keyword 'void' cannot be used in this context


namespace Microsoft.Internal.ManagedWPP
{
    [GeneratedCode("ManagedWPP", "1.20.0.0")]
    internal class WPP_83A9AC932ED24EB7846D1CA9FFBAF79E
    {
        private static Guid[] messageGuids;

        static WPP_83A9AC932ED24EB7846D1CA9FFBAF79E()
        {
            //was { new Guid("{2d854f00-4665-47ad-aff9-fdb6d2c8d46d}"), new Guid("{7ef2ea29-5c95-2ac0-8e0c-323b305dd3f9}"), new Guid("{c8ffcc26-fb67-8406-4ff7-d40abb918591}"), new Guid("{d2186831-7fc1-db36-1738-5efd34ded45f}"), new Guid("{d33f893d-1146-cf63-4ae5-3cb261a115a3}"), new Guid("{3b55f8d5-c19f-4318-6f55-83e21d00a99d}"), new Guid("{582a05fe-e4d8-0bdb-f1d3-b18591db6c1f}"), new Guid("{5ffd5e20-4286-b7ef-573e-c1c31aad11e9}"), new Guid("{6992561f-ac30-8b92-b64e-257350cd58f3}"), new Guid("{b9322a47-d7a5-35d9-aab1-7f6271fbf841}"), new Guid("{98503f53-45d4-c33f-a21b-f8b16b757623}"), new Guid("{8776bc0e-0a43-d9d6-dda6-1609f8d75a7a}"), new Guid("{2a715334-3df4-aa85-73e5-453465f502f3}") };
            Guid[] guid = new Guid[] { new Guid("{E6104BC1-2418-499B-910C-A2EEEFBD2FDC}"), new Guid("{FCFF27BF-6BEE-4151-8BD4-7EEB55A29527}") };
            WPP_83A9AC932ED24EB7846D1CA9FFBAF79E.messageGuids = guid;
        }

        [GeneratedCode("ManagedWPP", "1.20.0.0")]
        internal static unsafe void WPP_NOARGS(int messageGuidIndex, int messageNumber)
        {
            byte* bufferSize = stackalloc byte[TraceProvider.GetBufferSize(0, 0)];
            TraceProvider.InitializeTraceBuffer(bufferSize, WPP_83A9AC932ED24EB7846D1CA9FFBAF79E.messageGuids[messageGuidIndex], messageNumber);
            TraceHelper.traceProvider.TraceEvent(bufferSize);
        }

        [GeneratedCode("ManagedWPP", "1.20.0.0")]
        internal static unsafe void WPP_p(int messageGuidIndex, int messageNumber, IntPtr arg0)
        {
            int bufferSize = TraceProvider.GetBufferSize(1, Marshal.SizeOf(typeof(IntPtr)));
            Debug.Print(String.Format("QND- WPP_p buffer Size: {0}",bufferSize));
            byte* voidPointer = stackalloc byte[bufferSize];
            int num = 0;
            void* voidPointer1 = TraceProvider.InitializeTraceBuffer(voidPointer, WPP_83A9AC932ED24EB7846D1CA9FFBAF79E.messageGuids[messageGuidIndex], messageNumber, 1, ref num);
            Debug.Print(String.Format("QND- WPP_p after Trace Buffer: {0}", num));
            voidPointer1 = TraceProvider.InitializeTraceField(voidPointer1, arg0, voidPointer, ref num);
            Debug.Print(String.Format("QND- WPP_p after Trace Field: {0}", num));
            TraceHelper.traceProvider.TraceEvent(voidPointer);
            Debug.Print(String.Format("QND- WPP_p after TraceEvenmt"));
        }

        [GeneratedCode("ManagedWPP", "1.20.0.0")]
        internal static unsafe void WPP_ps(int messageGuidIndex, int messageNumber, IntPtr arg0, string arg1)
        {
            int bufferSize = TraceProvider.GetBufferSize(3, 2 + Marshal.SizeOf(typeof(IntPtr)));
            byte* voidPointer = stackalloc byte[bufferSize];
            int num = 0;
            void* voidPointer1 = TraceProvider.InitializeTraceBuffer(voidPointer, WPP_83A9AC932ED24EB7846D1CA9FFBAF79E.messageGuids[messageGuidIndex], messageNumber, 3, ref num);
            fixed (char* str = arg1)
            {
                char* offset = str;
                if (offset != null)
                {
                    offset = offset + RuntimeHelpers.OffsetToStringData;
                }
                voidPointer1 = TraceProvider.InitializeTraceField(voidPointer1, arg0, voidPointer, ref num);
                voidPointer1 = TraceProvider.InitializeTraceField(voidPointer1, offset, arg1.Length, voidPointer, ref num);
                TraceHelper.traceProvider.TraceEvent(voidPointer);
            }
        }
    }
}
